﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FishServe.Common.Services.Interface.Entities;
using Microsoft.Practices.Unity;
using FishServe.Client.Shell.Interface;
using FishServe.Core;

namespace FishServe.Client.Application
{
    internal class ApplicationModule : Module
    {
        private IShellModule _shellModule;
        private IEntityBuilderService _entityBuilderService;

        [Dependency]
        public IShellModule ShellModule
        {
            get { return _shellModule; }
            set { _shellModule = value; }
        }

        [Dependency]
        public IEntityBuilderService EntityBuilderService
        {
            get { return _entityBuilderService; }
            set { _entityBuilderService = value; }
        }
        
        public ApplicationModule(ModuleLoader moduleLoader, ModuleManifestResolver moduleManifestResolver) : base( moduleLoader, moduleManifestResolver)
        {
            // Root module must BuildUp itself after registered types are registered by the Module constructor.  
            // Also note the base() constructor in the ApplicationModule constructor signature which is only relevant for the 
            // root module.
            // All non-root modules, such as the ShellModule, CatchEffortAddIn module, must define a construct with the following 
            // signature:
            //
            //      [InjectionConstructor]
            //      public ShellModule([InjectChildContainer]IUnityContainer container) : base(container)
            //      {...}
            //
            // [Dependency] properties in the root container, i.e. ShellModule and EntityBuilderService, will be null until  
            // Container.BuildUp() is called.  All other non-root modules do not require Container.BuildUp() to be called, their
            // registered types will be registered and [Dependency] properties injected automatically.
            Container.BuildUp<ApplicationModule>(this);

            // Container.Resolve<IShellModule>().Show();
            _shellModule.Show();
        }
    }
}
